package com.hhc.controller;

import com.hhc.dto.OperationLogDTO;
import com.hhc.query.OperationLogQuery;
import com.hhc.service.OperationLogService;
import com.hhc.utils.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   操作日志Controller
 * </p>
 * @author pc
 */
@Slf4j
@RestController
@RequestMapping("/operation-log")
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    @PostMapping("/add")
    public RestResult<OperationLogDTO> addOperationLog(@Validated @RequestBody OperationLogDTO operationLogDTO) {
        OperationLogDTO result = operationLogService.createOperationLog(operationLogDTO);
        return RestResult.success(result);
    }

    @GetMapping("/list")
    public RestResult<Page<OperationLogDTO>> getOperationLogList(@Validated OperationLogQuery query) {
        Page<OperationLogDTO> result = operationLogService.getOperationLogList(query);
        return RestResult.success(result);
    }

    @DeleteMapping("/delete/{id}")
    public RestResult<Void> deleteOperationLog(@PathVariable Long id) {
        boolean deleted = operationLogService.deleteOperationLog(id);
        if (!deleted) {
            return RestResult.error("000001", "日志信息不存在");
        }
        return RestResult.success();
    }
}